from config import SCORE, ROLES


def get_type(count, block, empty):
    if empty <= 0:
        if count >= 5:
            return SCORE.FIVE
        if block == 0:
            return [0, SCORE.ONE, SCORE.TWO, SCORE.THREE, SCORE.FOUR][count]
        if block == 1:
            return [0, SCORE.BLOCKED_ONE, SCORE.BLOCKED_TWO, SCORE.BLOCKED_THREE, SCORE.BLOCKED_FOUR][count]
    elif empty == 1 or empty == count - 1:
        if count >= 6:
            return SCORE.FIVE
        if block == 0:
            return [0, 0, SCORE.TWO / 2, SCORE.THREE, SCORE.BLOCKED_FOUR, SCORE.FOUR][count]
        if block == 1:
            return [0, 0, SCORE.BLOCKED_TWO, SCORE.BLOCKED_THREE, SCORE.BLOCKED_FOUR, SCORE.BLOCKED_FOUR][count]
    elif empty == 2 or empty == count - 2:
        if count >= 7:
            return SCORE.FIVE
        if block == 0:
            return [0, 0, 0, SCORE.THREE, SCORE.BLOCKED_FOUR, SCORE.BLOCKED_FOUR, SCORE.FOUR][count]
        if block == 1:
            return [0, 0, 0, SCORE.BLOCKED_THREE, SCORE.BLOCKED_FOUR, SCORE.BLOCKED_FOUR, SCORE.FOUR][count]
        if block == 2:
            if count > 3:
                return SCORE.BLOCKED_FOUR
            else:
                return 0
    elif empty == 3 or empty == count - 3:
        if count >= 8:
            return SCORE.FIVE
        if block == 0:
            return [0, 0, 0, 0, SCORE.THREE, SCORE.THREE, SCORE.BLOCKED_FOUR, SCORE.FOUR][count]
        if block == 1:
            if count > 6:
                return SCORE.FOUR
            elif count > 3:
                return SCORE.BLOCKED_FOUR
            else:
                return 0
        if block == 2:
            if count > 3:
                return SCORE.BLOCKED_FOUR
            else:
                return 0
    elif empty == 4 or empty == count - 4:
        if count >= 9:
            return SCORE.FIVE
        if block == 0:
            if count > 4:
                return SCORE.FOUR
            else:
                return 0
        if block == 1:
            if count > 7:
                return SCORE.FOUR
            elif count > 3:
                return SCORE.BLOCKED_FOUR
        if block == 2:
            if count > 7:
                return SCORE.BLOCKED_FOUR
    elif empty == 5 or empty == count - 5:
        return SCORE.FIVE
    return 0


def modify_score(score):
    if SCORE.BLOCKED_FOUR < score < SCORE.FOUR:
        if SCORE.BLOCKED_FOUR < score < (SCORE.BLOCKED_FOUR + SCORE.THREE):
            return SCORE.THREE
        elif SCORE.BLOCKED_FOUR + SCORE.THREE < score < SCORE.BLOCKED_FOUR * 2:
            return SCORE.FOUR
        else:
            return SCORE.FOUR * 2
    return score
